
import { getDicts } from '@/api/system/dict/data'
/**
 * 获取字典数据
 */
export function useDict(args,store) {
  const res = ref({});
  return (() => {
    args.forEach((dictType, index) => {
      res.value[dictType] = [];
      const dicts = store.getters['dict/getDict'];
      // console.log(Object.keys(dicts).length,'dicts1111111111')
      if (Object.keys(dicts).length!= 0) {
        res.value[dictType] = dicts[dictType];
      } else {
        getDicts(dictType).then(resp => {
          res.value[dictType] = resp.data.map(p => ({ dictLabel: p.dictLabel, dictValue: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
          let dictData = { dictType: dictType, dictData: res.value[dictType] }
          // console.log(dictData,'dictData1111111111')
          store.commit('dict/setDict',dictData)
        })
      }
    })
    return toRefs(res.value);
  })()
}